#include "mainwindow.h"
#include "./ui_mainwindow.h"

#include <QLayout>
#include <QVBoxLayout>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    mainWidget = new QWidget(this);
    this->setCentralWidget(mainWidget);

    QVBoxLayout* layout = new QVBoxLayout();
    mainWidget->setLayout(layout);

    button = new QPushButton();
    button->setText("点击");
    button->setFixedSize(QSize(50, 50));

    layout->addWidget(button);

    button->installEventFilter(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}



bool MainWindow::eventFilter(QObject* object, QEvent* event)
{
    if (object == button)
    {
        if (event->type() == QEvent::MouseButtonPress)
        {
            qDebug() << "Button_Press";
        }
        else if (event->type() == QEvent::Enter)
        {
            qDebug() << "Button_Enter";
        }
        else if (event->type() == QEvent::Leave)
        {
            qDebug() << "Button_Leave";
        }

        return true;
    }
    // 交给其它事件处理器处理
    return QMainWindow::eventFilter(object, event);
}


void MainWindow::mousePressEvent(QMouseEvent* event)
{
    qDebug() << "button is pressed";
    event->accept();
}
